<template>
    <div>
        <el-dialog title="调用模板"  width="50vw" height="60vh" top="5vh" append-to-body :close-on-click-modal="false" :visible.sync="visible" v-if="visible"   @close="callback">
            <div style="text-align:right;display: block">
                <el-button type="primary" plain @click="keepSure()">确认</el-button>
                <el-button type="danger" plain @click="visible = false">取 消</el-button>
            </div> 
            <el-table
                ref="multipleTable"
                :data="tableData"
                tooltip-effect="dark"
                style="width: 100%;margin-top:10px"
                @selection-change="handleSelectionChange">
                <el-table-column
                type="selection"
                width="55">
                </el-table-column>
                <el-table-column
                label="模板名称"
                min-width="120">
                <template slot-scope="scope">{{ scope.row.fpName }}</template>
                </el-table-column>
                <el-table-column
                prop="createTime"
                label="日期"
                min-width="120">
                </el-table-column>
                <el-table-column
                    label="操作"
                    header-align="center"
                    align="center"
                    min-width="120"
                >
                    <template slot-scope="scope">
                        <el-button type="primary" plain @click="showData(scope.row)">查看</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="avue-crud__pagination">
                <el-pagination
                    @size-change="sizeChangeHandle"
                    @current-change="currentChangeHandle"
                    :current-page="pageIndex"
                    :page-sizes="[10, 20, 50, 100]"
                    :page-size="pageSize"
                    :total="totalPage"
                    background
                    layout="total, sizes, prev, pager, next, jumper">
                </el-pagination>
            </div>
            
        </el-dialog>
        <el-dialog title="模板详情"  width="50vw" height="60vh" top="5vh" append-to-body :close-on-click-modal="false" :visible.sync="visibleData" v-if="visibleData"   @close="callbackData">
            <el-button type="success" @click="keep()">复用模板</el-button>
            <el-table
                ref="multipleDataTable"
                :data="detailData"
                tooltip-effect="dark"
                style="width: 100%">
                <el-table-column
                label="奖金项名称"
                min-width="120"
                prop="jjxMc">
                </el-table-column>
                <el-table-column
                prop="fzName"
                label="分组名称"
                min-width="120">
                </el-table-column>
                <el-table-column
                prop="xsJe"
                label="金额"
                min-width="120">
                </el-table-column>
            </el-table>
            <span slot="footer" class="dialog-footer" style="text-align:center;display: block">
                <el-button @click="visibleData = false">取 消</el-button>
            </span> 
        </el-dialog>
    </div>
</template>

<script>
import {pageTemplate} from "@/api/jiangjin/jiangjinryfzb"
export default {
    name:"muban-table",
    data(){
        return{
            row:{},
            visibleData:false,
            visible:false,
            tableData:[],
            detailData:[],
            multipleSelection:[],
            pageSize:10,
            pageIndex:1,
            totalPage:0
        }
    },
    methods:{
        keep(){
            this.$emit('mubanTableChild',this.row)
            this.visibleData = false
            this.visible = false
        },
        handleSelectionChange(val){
            this.multipleSelection=val;
            
        },
        keepSure(){
            this.$message.closeAll()
            if(this.multipleSelection.length>1){
                this.$message.warning("只能选择一个模板")
                return false
            }
            if(this.multipleSelection.length==1){
                this.$emit('mubanTableChild',this.multipleSelection[0])
                this.visible=false
            }
        },
        init(fpId,fpType){
            this.visible=true
            this.getDataList(fpId,fpType)
        },
        getDataList(fpId,fpType){
            
            pageTemplate(Object.assign({
                size:this.pageSize,
                current:this.pageIndex
            },{fpId:fpId,fpType:fpType})).then(res=>{
                this.tableData=res.data.data.records
                //console.log("调用模板:"+JSON.stringify(res))
            })
        },
        // 每页数
        sizeChangeHandle(val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
        },
        // 当前页
        currentChangeHandle(val) {
        this.pageIndex = val
        this.getDataList()
        },
        callback(){
            this.visible = false
        },
        callbackData(){
            this.visibleData = false
        },
        showData(row){
            this.row = row
            this.visibleData = true
            this.detailData = JSON.parse(row.fpData)
        },
    }
}
</script>

<style>

</style>